﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.LazyLoadReference`1
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

using System;

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Serializable lazy reference to a UnityEngine.Object contained in an asset file.</para>
  /// </summary>
  [Serializable]
  public struct LazyLoadReference<T> where T : Object
  {
    private const int kInstanceID_None = 0;
    [SerializeField]
    private int m_InstanceID;

    public bool isSet => this.m_InstanceID != 0;

    public bool isBroken
    {
      get => this.m_InstanceID != 0 && !Object.DoesObjectWithInstanceIDExist(this.m_InstanceID);
    }

    public T asset
    {
      get
      {
        return this.m_InstanceID == 0 ? default (T) : (T) Object.ForceLoadFromInstanceID(this.m_InstanceID);
      }
      set
      {
        if ((Object) value == (Object) null)
          this.m_InstanceID = 0;
        else
          this.m_InstanceID = Object.IsPersistent((Object) value) ? value.GetInstanceID() : throw new ArgumentException("Object that does not belong to a persisted asset cannot be set as the target of a LazyLoadReference.");
      }
    }

    public int instanceID
    {
      get => this.m_InstanceID;
      set => this.m_InstanceID = value;
    }

    public LazyLoadReference(T asset)
    {
      if ((Object) asset == (Object) null)
        this.m_InstanceID = 0;
      else
        this.m_InstanceID = Object.IsPersistent((Object) asset) ? asset.GetInstanceID() : throw new ArgumentException("Object that does not belong to a persisted asset cannot be set as the target of a LazyLoadReference.");
    }

    public LazyLoadReference(int instanceID) => this.m_InstanceID = instanceID;

    public static implicit operator LazyLoadReference<T>(T asset)
    {
      return new LazyLoadReference<T>() { asset = asset };
    }

    public static implicit operator LazyLoadReference<T>(int instanceID)
    {
      return new LazyLoadReference<T>()
      {
        instanceID = instanceID
      };
    }
  }
}
